package com.yzf.web;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yzf.entity.Employee;
import com.yzf.service.SingleFileService;
import com.yzf.util.web.ServletUtil;

public class upload extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ServletUtil.forword(request, response, "upload");
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Map<String, String> map = ServletUtil.uploadFile(request);
		String name = map.get("name");
		String size = map.get("filesize");
		String filename = map.get("fileName");
		String type = map.get("type");
		
		String typeid = (String) ServletUtil.getSession(request).getAttribute("typeid");
		Employee em = (Employee) ServletUtil.getSession(request).getAttribute("employee");
		new SingleFileService().save(name,Long.valueOf(size),filename,typeid,em.getId(),type);
		ServletUtil.redirect(response, "/singlefile.jspx?id="+typeid);
	}

}
